﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using TransferPost.Beans;
using TransferPost.checkpoints;
using TransferPost.Componts;

namespace TransferPost.Forms
{
    /// <summary>
    /// 根据整改点自动生成要展示的，等下修改，先放个按钮
    /// </summary>
    [PostFormAttribute(FormName = "个性化整改扫描", FormNo = "003")]
    public partial class frmQACheckPoints : DockContentEx
    {
        public frmQACheckPoints()
        {
            InitializeComponent();
        }

        public frmQACheckPoints(frmMain frm)
        {
            frm_Parent = frm;

            InitializeComponent();
        }

        /// <summary>
        /// TODO:统一取消
        /// </summary>
        /// <param name="msg"></param>
        private void OutPutBootmMsg(string msg)
        {
            //PostContext.Instance.MyLogger.Info(msg);

            frm_Parent.AppendText(string.Format("{0} {1}{2}", DateTime.Now.ToString(), msg, System.Environment.NewLine));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string strRootPath = "d:\\ywcode";

            Dictionary<string, object> args = new Dictionary<string, object>();
            args.Add("rootpath", strRootPath);
            args.Add("findpros", null);

            C_QA_T_YW_2003_092 cc = new C_QA_T_YW_2003_092();

            // 检索出来要处理的文件夹列表
            if (cc.PrepareCheck(args) == false)
            {
                OutPutBootmMsg(">>>> 4.出现异常");
            }
            else
            {
                List<SVNProjectInfo> findpros = args["findpros"] as List<SVNProjectInfo>;


                if (findpros.Count > 0)
                {
                    OutPutBootmMsg(string.Format("共检测到共有{0}个工程中存在个性化文件特征点", findpros.Count));

                    // 执行检查动作
                    cc.DoCheck(args);

                    // 检测不通过的
                    var NoPassPro = from v in cc.AnalysisRtn
                                    where v.Value.Exists(y => y.CheckIsOk == false)
                                    select v;

                    // 存在无需修改文件的清单
                    var NoNeedCheck = from v in cc.AnalysisRtn
                                      where v.Value.Exists(y => y.NoCheckRequired == true) && v.Value.All(y => y.CheckIsOk = true)
                                      select v;

                    // 检测通过
                    var PassPro = from v in cc.AnalysisRtn
                                  where v.Value.All(y => y.CheckIsOk = true)
                                  select v;

                    OutPutBootmMsg(string.Format(">>通过{0},不通过{1}", PassPro.Count(), NoPassPro.Count()));

                    OutPutBootmMsg(string.Format(">>通过项目但是存在无需整改如下："));

                    foreach (var item in NoNeedCheck)
                    {
                        OutPutBootmMsg(string.Format("{0} 存在无需整改", item.Key.ProjectName));
                    }

                    OutPutBootmMsg(string.Format(">>>>>整改检测不通过的清单如下："));

                    foreach (var item in NoPassPro)
                    {
                        OutPutBootmMsg(string.Format("{0} 检测失败", item.Key.ProjectName));

                        foreach (var ss in item.Value)
                        {
                            OutPutBootmMsg(string.Format(">>>>>>问题文件为", ss.filePath));
                        }
                    }
                }
                else
                {
                    OutPutBootmMsg(string.Format("没有需要检测的文件发现，此检测终止"));
                }
            }
        }
    }
}
